package com.ftx.controller.test.lock;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * Created by fengtingxin on 2020/10/17.
 */
public class ExecuteClass {

    private static boolean T2Run = false; //标识位，用来通知T2线程执行

    private static boolean T3Run = false;


    public static void main(String[] args) {

        BigDecimal bigDecimal = new BigDecimal(1.01);
        Long temp = new Long(1);
        BigDecimal bigDecimal1 = new BigDecimal(temp);
        System.out.println(bigDecimal1);
        System.out.println(bigDecimal.setScale(0, RoundingMode.HALF_UP));

        Object lock1 = new Object();
        Object lock2 = new Object();

        Thread T1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock1){
                    System.out.println("T1 run");
                    //t1 线程通知t2执行
                    T2Run = true;
                    lock1.notify();
                }
            }
        });
        Thread T2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock1){
                    if(!T2Run){
                        System.out.println("T2 wait");
                        try {
                            lock1.wait();
                        } catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                    System.out.println("T2 run");
                    //t2 线程通知t3执行
                    synchronized (lock2){
                        T3Run = true;
                        lock2.notify();

                    }
                }
            }
        });

        Thread T3 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (lock2){
                    if (!T3Run){
                        System.out.println("T3 wait");
                        try {
                            lock2.wait();
                        } catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                    System.out.println("T3 run");
                }
            }
        });
        T1.start();
        T2.start();
        T3.start();




//        MyThread thread1 = new MyThread(demo);
//        thread1.setName("thread1");
//        MyThread thread2 = new MyThread(demo);
//        thread2.setName("thread2");
//        MyThread thread3 = new MyThread(demo);
//        thread3.setName("thread3");
//        MyThread thread4 = new MyThread(demo);
//        thread4.setName("thread4");
//        MyThread thread5 = new MyThread(demo);
//        thread5.setName("thread5");
//
//        thread1.start();
//        System.out.println("currentThread Name is " + Thread.currentThread().getName() + " 状态为：" + Thread.currentThread().getState());
//
//        demo.signal();
//        thread2.start();
//        thread3.start();
//        thread4.start();
//        thread5.start();
    }


}
